package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.CharSkillTable;
import com.lineage.server.datatables.storage.CharSkillStorage;
import com.lineage.server.templates.L1UserSkillTmp;
import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CharSkillReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final CharSkillStorage _storage = (CharSkillStorage)new CharSkillTable();
  
  private static CharSkillReading _instance;
  
  public static CharSkillReading get() {
    if (_instance == null)
      _instance = new CharSkillReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public ArrayList<L1UserSkillTmp> skills(int playerobjid) {
    ArrayList<L1UserSkillTmp> tmp;
    this._lock.lock();
    try {
      tmp = this._storage.skills(playerobjid);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void spellMastery(int playerobjid, int skillid, String skillname, int active, int time) {
    this._lock.lock();
    try {
      if (skillname.equals("none"))
        return; 
      this._storage.spellMastery(playerobjid, skillid, skillname, active, time);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void spellLost(int playerobjid, int skillid) {
    this._lock.lock();
    try {
      this._storage.spellLost(playerobjid, skillid);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public boolean spellCheck(int playerobjid, int skillid) {
    boolean tmp;
    this._lock.lock();
    try {
      tmp = this._storage.spellCheck(playerobjid, skillid);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void setAuto(int mode, int objid, int skillid) {
    this._lock.lock();
    try {
      this._storage.setAuto(mode, objid, skillid);
    } finally {
      this._lock.unlock();
    } 
  }
}
